Skip to content

Give allow_net bwrap jails a private network through pasta - #170

Merged
M3gA-Mind merged 9 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/p8-bwrap-pasta-net
Nov 12, 2026
Merged

M3gA-Mind merged 9 commits into
tinyhumansai:mainfrom
M3gA-Mind:feat/p8-bwrap-pasta-net

Conversation

@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Stacked on #161 (which contains #160): it keeps their descriptor contract. Review it after those, or read only the last commit.

Summary

A bwrap jail that allows network shared the host's network namespace. So host loopback services and abstract unix sockets were reachable from it, and it stayed Process, which native_jail::prepare refuses when require_process_isolation is set. tinymcp and OpenHuman set exactly that for registry-installed stdio MCP servers, so every one of them was refused on Linux.

When a root-owned pasta (passt) and nsenter are found at fixed paths and pass a probe, an allow_net jail now gets a private network:

  1. pasta starts a holder (sh -c 'read _') that owns a fresh user, network and pid namespace.
  2. The launcher enters the holder's user and network namespace with nsenter --user --net --preserve-credentials. It enters by namespace descriptor (/proc/self/fd/N), opened once after checking that the pid is pasta's child and that its network namespace is not the host's. Then it runs bwrap, without --unshare-net.
  3. pasta is only ever started with --config-net --no-map-gw -T none -U none --dns-forward 169.254.1.1: no port forwarding either way, no gateway mapping to the host, DNS through one forwarded address. The jail gets its own /etc/resolv.conf naming that address, via --ro-bind-data. The host's resolv.conf (often a symlink into /run) is not bound.
  4. The holder reads a pipe whose only writer, once the jail starts, is bwrap's --sync-fd. When bwrap exits, normally or killed, the holder sees end-of-file and exits, and pasta with it. Before the hand-over, dropping the Network kills pasta. So no pasta outlives a jail.
  5. isolation_for reports Kernel for such a jail. Without a working pasta nothing changes: the host network is shared, and the jail stays Process.

Why not pasta -- bwrap, which the issue suggested: pasta closes every inherited descriptor above 2 at startup. bwrap would then lose its argument file (--args 9), the --bind-fd grant descriptors (#160) and the seccomp filters (#161). We confirmed this on ubuntu-latest ("Can't read --args data: Bad file descriptor").

Why not slirp4netns, or attaching pasta to the namespaces bwrap creates: both join an existing namespace. Ubuntu's AppArmor user-namespace restriction (apparmor_restrict_unprivileged_userns=1) refuses that setns, with "Operation not permitted" from both tools. slirp4netns has no mode that creates the namespace itself, so it is left out.

Related issue

Closes #109.

API or behavior changes

  • New: BubblewrapBackend::networks_privately().
  • isolation_for / is_suitable_for_untrusted_jail now return Kernel / true for an allow_net jail when networks_privately().
  • Behaviour change on hosts with pasta: an allow_net jail no longer reaches host loopback services, the host through its gateway address, or host abstract sockets. Outbound connections and DNS work.
  • Nothing changes where pasta or nsenter is missing.

Validation

Commands actually run, on our Linux CI runner (no pasta installed there) at 4e06be4 (bubblewrap 0.9.0):

  • cargo fmt --all -- --check: clean
  • cargo clippy --all-targets --all-features -- -D warnings: 0 warnings (--keep-going, all targets)
  • cargo build --all-targets --all-features: ok
  • cargo test --all-features: 1608 passed, 0 failed, 5 ignored; bwrap::pasta::tests 9, bwrap::launcher::tests 11, bwrap::tests 17
  • Real bwrap suites with TINYBOX_REQUIRE_BWRAP=1: bwrap_isolation 24/0, bwrap_fd_leak 2/0, bwrap_pasta_live 3/0 (all three skipped there: no pasta)

That runner has no pasta, so the live pasta tests skip there. The new CI job bwrap-pasta-live runs them on ubuntu-latest, with passt installed and TINYBOX_REQUIRE_PASTA=1. The same shape was proven there first, by hand, with a probe:

  • outbound HTTPS 200;
  • host 127.0.0.1 refused; gateway address refused; host abstract socket refused;
  • --args/--bind-fd descriptors intact;
  • no pasta left after bwrap exits or is SIGKILLed.

Tests

  • Unit tests (pasta_tests, launcher_tests, mod_tests):
    • the only pasta flags allowed, plus a forbidden-flag list;
    • trusted-path lookup;
    • /proc children, PPid and route-table parsing;
    • the ready-timeout error;
    • refusal of a pid that is not pasta's child, or that shares this process's network;
    • the nsenter prefix by descriptor;
    • --ro-bind-data/--sync-fd wiring, without --unshare-net and without the host resolv.conf;
    • Kernel only with a working pasta.
  • Live tests (tests/bwrap_pasta_live.rs, live_*):
    • the reachability matrix: outbound reached; host loopback, gateway and host abstract socket refused;
    • killing a jail leaves no pasta;
    • a jail that exits leaves no pasta.
  • bwrap_isolation.rs: the two tests that assumed allow_net shares the host network now expect isolation when networks_privately() is true, and the old behaviour otherwise.
  • Not unit-tested: Pasta::start and the holder lookup against a real pasta. The live tests cover them, because they need pasta.

Documentation

The bwrap module docs have a new "Private network" section and updated "What is claimed". pasta.rs documents the design and why it is shaped this way.

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

A jail that allows network shared the host's network namespace, so host
loopback services and abstract sockets were reachable from it and the
jail stayed Process, which native_jail refuses when process isolation
is required. Every registry-installed stdio MCP server was refused on
Linux for that reason.

When a root-owned pasta and nsenter are found and pass a probe, pasta
now starts a holder that owns a fresh user and network namespace, and
the launcher enters it with nsenter by namespace descriptor before it
runs bwrap. pasta closes every inherited descriptor, so it cannot be
bwrap's parent; the holder keeps the argument file, grant and seccomp
descriptors intact. pasta runs only with no port forwarding, no gateway
mapping and DNS through one forwarded address, and the jail gets its
own resolv.conf. The holder lives exactly as long as bwrap through
--sync-fd, so no pasta outlives a jail, even a killed one. Such a jail
reports Kernel. Without pasta nothing changes: the host network is
shared and the jail stays Process.

slirp4netns is not used: it only attaches to an existing namespace,
which Ubuntu's AppArmor user-namespace restriction refuses.
@M3gA-Mind

Copy link
Copy Markdown
Collaborator Author

Stacked on #161 (which contains #160). Please merge #160, then #161, then this; until then this PR's diff shows their commits too. The live pasta reachability, fd and no-orphan tests run in this PR's bwrap-pasta-live job on ubuntu-latest.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 56ddb329-ed88-4296-ac1b-0eba8622c3cf
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@tinysweeper

tinysweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 83e3a890514fb9551059f502c01fcb6e3a20afef

Findings

No active actionable findings.

Resolved this pass

  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping
  • Pass the python script without single-quote wrapping

Verdict: Ready for maintainer review · Priority: none
Coverage: Reviewed 11 of 11 files.

Diagnostics and supporting details

Full summary

Pull request purpose (title): Give allow_net bwrap jails a private network through pasta. Tiny Sweeper completed its review; deterministic results follow.

Review snapshot

Change surface Files Review signal Count
Production 4 Active findings 0
Tests 6 Noted findings 0
Documentation 0 Resolved findings 9
Configuration 1 Pending checks/questions 0

Completeness: Complete
Test assessment: Test coverage is assessed from changed tests and lane evidence; execution is not claimed without trusted check data.

What changed

Adds a private network layer for `allow_net` bwrap jails using `pasta`: trusted-path lookup and a probe for `pasta`/`nsenter`, a holder process whose user and network namespaces are entered by descriptor with `nsenter`, a jail-local `/etc/resolv.conf`, and `--sync-fd` so the holder and `pasta` exit when `bwrap` does. `isolation_for` reports `Kernel` for a privately networked `allow_net` jail, and a `pasta` start failure refuses the jail. Adds a `private_resolv` mount option so the host's `/etc/resolv.conf` is left out of the baseline, and a `bwrap-pasta-live` CI job that installs passt and util-linux and runs the live suites with `TINYBOX_REQUIRE_PASTA=1`. The latest-push delta is unavailable.

Features

  • Added — nsenter-by-descriptor launcher entry: The launcher runs under `nsenter --user=/proc/self/fd/N --net=/proc/self/fd/N --preserve-credentials --` by descriptor, so a reused pid cannot redirect namespace entry; the shell then closes everything outside its keep list. That keep-list arithmetic is where the open defect and the bash-version concern live. (crates/tinybox-jail/src/bwrap/launcher.rs impl ArgsFile {, crates/tinybox-jail/src/bwrap/mod.rs fn prepare_command(verified: &Verified, jail: &Jail, cmd: &Command) -> io::Resul, crates/tinybox-jail/src/bwrap/launcher_tests.rs fn the_grant_descriptors_reach_bwrap_and_nothing_else_does() -> io::Result<()> {)
  • Added — Private resolver and closed-down pasta flags: `pasta` is only started with `--config-net --no-map-gw -T none -U none --dns-forward 169.254.1.1`, and the jail gets a descriptor-bound `/etc/resolv.conf` naming that address while the host's is left out of the baseline, so outbound and DNS work but host loopback, the gateway and host abstract sockets are unreachable. (crates/tinybox-jail/src/bwrap/args.rs fn baseline_mounts() -> Vec<Mount> {, crates/tinybox-jail/src/bwrap/args.rs pub(super) struct Options {, crates/tinybox-jail/src/bwrap/mod.rs fn prepare_command(verified: &Verified, jail: &Jail, cmd: &Command) -> io::Resul)
  • Added — CI job for live pasta reachability: A new `bwrap-pasta-live` job installs bubblewrap/passt/util-linux and runs the pasta live, isolation and fd-leak suites with `TINYBOX_REQUIRE_PASTA=1`, so a missing private network fails rather than skips; actions are pinned by SHA. (.github/workflows/ci.yml jobs:)

Tests

  • unit — `pasta_tests` assert the closed-down `pasta` flags against a forbidden list, the resolver contents, trusted-path lookup, `/proc` children/PPid/route parsing, the ready timeout, refusal of a pid that is not `pasta`'s child or shares this process's network, and a fake network's descriptor duplication and release without a process.: Added in the diff; the tests lane answered and did not raise a defect here. (crates/tinybox-jail/src/bwrap/pasta_tests.rs)
  • unit — Launcher tests assert only numbered grant descriptors reach bwrap while a stray inheritable descriptor is closed, that the launcher runs with an empty environment, and that with namespace entry `nsenter` is the program with `--user=/proc/self/fd/14 --net=/proc/self/fd/15 --preserve-credentials --`; the new test also asserts the keep count is 4, which is the bash-version-dependent concern.: Added in the diff; the tests lane answered and left one bash-version-dependent `-ge` concern in the descriptor-closing loop. (crates/tinybox-jail/src/bwrap/launcher_tests.rs fn the_args_file_is_gone_once_the_launcher_has_started_bwrap() -> io::Result<()>, crates/tinybox-jail/src/bwrap/launcher_tests.rs fn the_grant_descriptors_reach_bwrap_and_nothing_else_does() -> io::Result<()> {, crates/tinybox-jail/src/bwrap/launcher_tests.rs fn the_launcher_runs_with_an_empty_environment() -> io::Result<()> {)
  • unit — `args_tests` cover grants bound from descriptors with baseline paths by path, a symlink swapped in after the check not being followed, a symlink above a grant left to the host, a missing read-only grant skipped, and path binding when descriptor support is absent; the new `private_resolv` option is threaded through the test fixtures.: Added/modified in the diff; the tests lane answered and did not raise a defect here. (crates/tinybox-jail/src/bwrap/args_tests.rs fn a_denial_through_a_baseline_symlink_also_covers_the_link_target() -> io::Resu, crates/tinybox-jail/src/bwrap/args_tests.rs fn disable_userns_is_omitted_when_the_probe_found_no_support() -> io::Result<()>, crates/tinybox-jail/src/bwrap/args_tests.rs use super::*;)
  • integration — Live pasta tests assert outbound reachability with host loopback, gateway and abstract sockets refused, only stdio open in the jail, and no `pasta` outliving a killed or exited jail; they skip unless the backend networks privately, and `TINYBOX_REQUIRE_PASTA=1` makes a missing private network a failure.: Added in the diff; the tests lane answered and did not raise a defect here; these are the tests the new CI job is intended to exercise. (crates/tinybox-jail/tests/bwrap_pasta_live.rs)
  • integration — Isolation tests now expect `allow_net` to reach host loopback only when the host network is shared, and expect a privately networked backend to be suitable for an untrusted jail at `Process` or above.: Modified in the diff; the tests lane answered and did not raise a defect here. (crates/tinybox-jail/tests/bwrap_isolation.rs fn network_is_unreachable_when_denied_and_reachable_when_shared() -> io::Result<, crates/tinybox-jail/tests/bwrap_isolation.rs fn only_a_jail_with_a_private_network_is_suitable_for_untrusted_code() -> io::Re)

Before merge

None.

How this fits together

flowchart LR
  n0["baseline_mounts<br/>changed"]:::changed
  n1["replaces_private_mount<br/>changed"]:::changed
  n2["...eline_symlink_also_covers_the_link_target<br/>changed"]:::changed
  n3["...s_omitted_when_the_probe_found_no_support<br/>changed"]:::changed
  n4["ArgsFile<br/>changed"]:::changed
  n5["...s_file_fails_closed_without_running_bwrap<br/>changed"]:::changed
  n6["run<br/>changed"]:::changed
  n7["tempdir"]:::impacted
  n8["discard"]:::impacted
  n9["shell"]:::impacted
  n10["stand_in"]:::impacted
  n11["tmp"]:::impacted
  n12["jail_args_with_fds"]:::impacted
  n2 -->|calls| n7
  n2 -->|tests| n7
  n3 -->|calls| n7
  n3 -->|tests| n7
  n5 -->|uses| n4
  n5 -->|calls| n7
  n5 -->|tests| n7
  n5 -->|calls| n9
  n5 -->|tests| n9
  n5 -->|calls| n10
  n5 -->|tests| n10
  n6 -->|calls| n7
  n6 -->|calls| n8
  n6 -->|calls| n10
  n6 -->|calls| n11
  n12 -->|calls| n0
  n12 -->|calls| n1
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 8 files; 0 findings.

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Reviewed 8 files; 0 findings.

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The tests lane answered in full and reported no test that cannot fail, while leaving one bash-version-dependent `-ge` concern in the descriptor-closing loop and one earlier finding still open; `Pasta::start` and holder lookup are not unit-tested against a real `pasta`.
  • Lane summary: Adds a private network layer to the bwrap backend using `pasta`, with the holder lifecycle and `nsenter` integration. Appears sound for its scope; unit and integration tests cover the new failure modes and the live behaviour. (1 earlier finding(s) still open)

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The commits lane answered and reported no sensitive content in committed files, with one earlier finding still open.
  • Lane summary: No sensitive content in committed files. (1 earlier finding(s) still open)

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The description lane answered, confirmed the earlier disputed python-probe quoting finding no longer applies, and identified the launcher keep-list defect described in changes.
  • Lane summary: This revision adds the CI job for the pasta live tests, the `private_resolv` mount option, the `nsenter` prefix by namespace descriptor in the launcher, and the `pasta` backend wiring; the pinned actions and read-only `permissions` are unchanged and no untrusted context reaches a shell. I found no defect in the code changed since the last review.
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash, deepseek-v4-flash
  • Spend: $0.036575
  • Completion usage: incomplete; some provider completion costs are unavailable.
  • Tokens: 1254353 input · 98705 output · 200606 cached · 808 embedding
  • Updated: 2026-11-12T14:31:03Z
  • Continuity: summary cache chain restarted at the storage ceiling.
Head State Pass summary
2b160c20bbd2 incomplete 0 active finding(s), 10 resolved finding(s) (at 2026-11-11T13:36:57Z)
87c539ac6c03 ready for maintainer review 0 active finding(s), 12 resolved finding(s) (at 2026-11-11T13:39:38Z)
1f71db953749 incomplete 0 active finding(s), 12 resolved finding(s) (at 2026-11-11T14:13:32Z)
6418fe4cc133 incomplete 0 active finding(s), 7 resolved finding(s) (at 2026-11-12T07:34:46Z)
83e3a890514f ready for maintainer review 0 active finding(s), 9 resolved finding(s) (at 2026-11-12T14:31:03Z)

tinysweeper 0.1.2

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: 1 lane(s) blocking, worst finding is high.

Fix or reply to the findings below and push. The next review clears this automatically once they are gone — you should not need to dismiss anything by hand.

Diagnostics

Total spend: $0.0149

@tinysweeper tinysweeper Bot added the priority: p1 Next. Wrong behaviour a user will hit, or a security weakness behind a condition. label Nov 11, 2026
ubuntu-latest is rolling to Ubuntu 24.04, where AppArmor denies
unprivileged user namespaces to programs without a profile for them,
which is every bwrap jail the job starts, so the backend found no
working bwrap and every live test failed before reaching pasta. Lift it
the way the native-resource job already does, and print the bwrap and
pasta versions the run used.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper could not complete coverage (4 unanswered item(s)), so this is not an approval.

Diagnostics

Total spend: $0.0414

@tinysweeper tinysweeper Bot added priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. and removed priority: p1 Next. Wrong behaviour a user will hit, or a security weakness behind a condition. labels Nov 11, 2026
On x86 with AVX2 pasta re-executes itself as pasta.avx2, so the live
tests' lookup by process name found no pasta and both lifetime tests
failed although the jail ran on its network. Match the name by prefix.
A connect to the unmapped gateway is dropped rather than refused, so
the reachability probe waited out the TCP timeout (132 s on CI); bound
each connect to 5 s.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previously-blocking findings are resolved. Clearing the changes request.

Diagnostics

Total spend: $0.0095

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: 1 lane(s) blocking, worst finding is low.

Fix or reply to the findings below and push. The next review clears this automatically once they are gone — you should not need to dismiss anything by hand.

Diagnostics

Total spend: $0.0138

@tinysweeper tinysweeper Bot added priority: p1 Next. Wrong behaviour a user will hit, or a security weakness behind a condition. and removed priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. labels Nov 11, 2026

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper could not complete coverage (4 unanswered item(s)), so this is not an approval.

Diagnostics

Total spend: $0.0255

@tinysweeper tinysweeper Bot added priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. and removed priority: p1 Next. Wrong behaviour a user will hit, or a security weakness behind a condition. labels Nov 12, 2026

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previously-blocking findings are resolved. Clearing the changes request.

Diagnostics

Total spend: $0.0366

@tinysweeper tinysweeper Bot added priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. and removed priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. labels Nov 12, 2026
@M3gA-Mind
M3gA-Mind merged commit fffbf09 into tinyhumansai:main Nov 12, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bwrap jail: isolated networking (pasta/slirp4netns) so allow_net jails keep Kernel isolation

1 participant